package com.bright.werk_ai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bright.werk_ai.entity.User;
import com.bright.werk_ai.exception.BusinessException;
import com.bright.werk_ai.mapper.UserMapper;
import com.bright.werk_ai.response.ResultCode;
import com.bright.werk_ai.service.UserService;
import com.bright.werk_ai.vo.UserVO;
import org.springframework.stereotype.Service;

/**
 * @author LeiFengLiang
 * @Description: 用户实现类
 * @Classname: UserServiceImpl
 * @date 2022-05-18 15:04
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {
    /**
     * @Description 实现用户登录验证
     * @Date 2022/5/18 15:27
     * @Param [UserVO]
     * @return com.bright.werk_ai.vo.UserVO
     **/
    @Override
    public UserVO login(UserVO UserVO) {
        UserVO token = null;
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", UserVO.getUsername());

        User account = this.baseMapper.selectOne(wrapper);
        if (account != null) {
            if (UserVO.getPassword().equals(account.getPassword())) {
                token = UserVO;
                token.setId(account.getId());
            }
        } else {
            token=null;
        }
        return token;
    }

}
